<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加数据</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/x_mgr/start/layui/css/layui.css" media="all">
    <style>
        body {
            padding: 10px;
            font-size: 14px;
            background: #fff;
            width: 95%;
            margin: 0 auto;
            font-size: 14px;
            line-height: 20px;
            overflow: scroll;
        }
        p {
            margin-bottom: 10px;
        }
        input {
            border: 1px solid #3cc51f;
            padding: 5px 10px;
            margin: 0 10px 10px 0;
        }
    </style>
</head>
<body>
<div class="layui-card-body" style="padding: 15px;">
    <form class="layui-form" action="" lay-filter="operate-form-group">
        <div class="layui-tab layui-tab-brief">
            <div class="layui-tab-content">
                <div class="layui-form-item">
                    <label class="layui-form-label">渠道商名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="channelMchName" lay-verify="title" autocomplete="off" placeholder="请输入渠道商名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">上级渠道代理商</label>
                    <div class="layui-input-block">
                        <select name="supChannelMchAgentId" id="supChannelMchAgentId" lay-filter="supChannelMchAgentId">
                            <option value="">请选择</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">登录用户名</label>
                   <div class="layui-input-block">
                        <input type="text" id="userName" name="userName" lay-verify="required" placeholder="输入用户登录名" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">真实姓名</label>
                    <div class="layui-input-block">
                        <input type="tel" id="realName" name="realName" placeholder="输入真实姓名" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">身份证号</label>
                    <div class="layui-input-block">
                        <input type="text" id="idCard" name="idCard" placeholder="输入身份证号" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">手机号</label>
                    <div class="layui-input-block">
                        <input type="tel" id="mobile" name="mobile" lay-verify="phone" placeholder="输入手机号" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">QQ号</label>
                    <div class="layui-input-block">
                        <input type="text" id="qq" name="qq" placeholder="输入QQ号" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">邮箱</label>
                    <div class="layui-input-block">
                        <input type="text" id="email" name="email" lay-verify="email" placeholder="输入邮箱" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">渠道商状态</label>
                        <div class="layui-input-inline">
                            <input type="radio" name="status" value="1" title="开启" checked="true">
                            <div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon"></i>
                                <div>开启</div>
                            </div>
                            <input type="radio" name="status" value="0" title="禁止">
                            <div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i>
                                <div>禁止</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block" style="padding-bottom: 20px;">
                    <button type="button" class="layui-btn" lay-submit="" lay-filter="mchAdd">新增</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </div>
    </form>
</div>
<script src="/x_mgr/start/layui/layui.js"></script>
<script>
    layui.use(['layer', 'form'], function(){
        var $ = layui.$
            ,layer = layui.layer

            ,index = parent.layer.getFrameIndex(window.name) //获取窗口索引
            ,element = layui.element
            ,form = layui.form;

        form.render(null, 'operate-form-group');
        /* 自定义验证规则 */
        form.verify({
            title: function(value){
                if(value.length < 2){
                    return '渠道商名称至少得2个字';
                }
            }
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });
        /* 监听提交 */
        form.on('submit(mchAdd)', function(data){
            console.log(JSON.stringify(data.field));
            $.ajax({
                cache:true,
                type:"POST",
                url: '/api'+ '/channelmch_info/add',
                data:data.field,
                async:false,
                error:function(request){//请求失败之后的操作
                    layer.alert(res.msg, {title: "提示",icon: 6},function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);

                    });
                },
                success:function(res){//请求成功之后的操作
                    if(res.code == 0) {

                        layer.alert(res.msg, {title: "提示",icon: 6},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);

                        });
                    }else{
                        layer.alert(res.msg, {title: "提示",icon: 6},function () {
                            // 获得frame索引
                            // var index = parent.layer.getFrameIndex(window.name);
                            // //关闭当前frame
                            // parent.layer.close(index);

                        });
                    }
                }
            });
        });

      //  form.on('select(supChannelMchAgentId)', function(data){
            //   alert(data.value); // 获取选中的值
            $.ajax({
                cache:false,
                type:"POST",
                url: '/api'+ '/channelagentmch_info/getSupChannelAgentMch',
                data: {
                    channelAgentMchLevel: 4,
                },
                async:false,
                error:function(request){//请求失败之后的操作

                },
                success:function(res){//请求成功之后的操作
                    if(res.code == 0) {
                        $("#supChannelMchAgentId").find("option").remove();
                        $("#supChannelMchAgentId").append('<option value="0">请选择上级渠道代理商(默认不选,无上级)</option>');
                        var channelMchAgentList = res.data;
                        //遍历赋值
                        for(var i in channelMchAgentList){
                            if(channelMchAgentList[i].channelAgentMchLevel == 1){
                                $("#supChannelMchAgentId").append('<option value= '+channelMchAgentList[i].channelAgentMchId+'>'+ '[高级渠道代理商]  ' +channelMchAgentList[i].channelAgentMchName +'</option>');
                            }else if (channelMchAgentList[i].channelAgentMchLevel == 2){
                                $("#supChannelMchAgentId").append('<option value= '+channelMchAgentList[i].channelAgentMchId+'>'+ '[中级渠道代理商]  ' +channelMchAgentList[i].channelAgentMchName +'</option>');
                            }else{
                                $("#supChannelMchAgentId").append('<option value= '+channelMchAgentList[i].channelAgentMchId+'>'+ '[普通渠道代理商]  ' +channelMchAgentList[i].channelAgentMchName +'</option>');

                            }
                        }
                        form.render('select');
                    }
                }
            });

   //     });

//        // 加载上级渠道代理
//        $.ajax({
//            type: 'post',
//            url: '/api'+ '/config/common/pay_product_all',
//            error: function(err){
//                layer.alert(err);
//            },
//            success: function(res){
//                if(res.code == 0){
//                    var payProductList = res.data;
//                    //遍历赋值
//                    for(var i in payProductList){
//                        $("#productId").append('<option value= '+payProductList[i].id+'>'+payProductList[i].productName+'</option>');
//                    }
//                    form.render('select');
//                }
//            }
//        });

        $('.layui-btn-container .layui-btn').on('click', function(){
            var othis = $(this)
                ,type = othis.data('type');
            active[type] && active[type].call(this);
        });
    });
</script>
</body>
</html>
